﻿using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a CNN OCR classifier.</summary>
	// Token: 0x02000052 RID: 82
	[Serializable]
	public class HOCRCnn : HHandle, ISerializable, ICloneable
	{
		// Token: 0x06000BCB RID: 3019 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HOCRCnn() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06000BCC RID: 3020 RVA: 0x0004ABF7 File Offset: 0x00048DF7
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HOCRCnn(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000BCD RID: 3021 RVA: 0x0004AC06 File Offset: 0x00048E06
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HOCRCnn(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000BCE RID: 3022 RVA: 0x0004AC15 File Offset: 0x00048E15
		private void AssertSemType()
		{
			base.AssertSemType("ocr_cnn");
		}

		// Token: 0x06000BCF RID: 3023 RVA: 0x0004AC22 File Offset: 0x00048E22
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HOCRCnn obj)
		{
			obj = new HOCRCnn(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000BD0 RID: 3024 RVA: 0x0004AC3C File Offset: 0x00048E3C
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HOCRCnn[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HOCRCnn[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HOCRCnn(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Read an CNN-based OCR classifier from a file.
		///   Modified instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="fileName">File name. Default: "Universal_Rej.occ"</param>
		// Token: 0x06000BD1 RID: 3025 RVA: 0x0004ACAC File Offset: 0x00048EAC
		public HOCRCnn(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(2082);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		// Token: 0x06000BD2 RID: 3026 RVA: 0x0004ACF8 File Offset: 0x00048EF8
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = this.SerializeOcrClassCnn();
			byte[] value = hserializedItem;
			hserializedItem.Dispose();
			info.AddValue("data", value, typeof(byte[]));
		}

		// Token: 0x06000BD3 RID: 3027 RVA: 0x0004AD30 File Offset: 0x00048F30
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HOCRCnn(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = new HSerializedItem((byte[])info.GetValue("data", typeof(byte[])));
			this.DeserializeOcrClassCnn(hserializedItem);
			hserializedItem.Dispose();
		}

		/// <summary>Serialize object to binary stream in HALCON format</summary>
		// Token: 0x06000BD4 RID: 3028 RVA: 0x0004AD70 File Offset: 0x00048F70
		public new void Serialize(Stream stream)
		{
			HSerializedItem hserializedItem = this.SerializeOcrClassCnn();
			hserializedItem.Serialize(stream);
			hserializedItem.Dispose();
		}

		/// <summary>Deserialize object from binary stream in HALCON format</summary>
		// Token: 0x06000BD5 RID: 3029 RVA: 0x0004AD84 File Offset: 0x00048F84
		public new static HOCRCnn Deserialize(Stream stream)
		{
			HOCRCnn hocrcnn = new HOCRCnn();
			HSerializedItem hserializedItem = HSerializedItem.Deserialize(stream);
			hocrcnn.DeserializeOcrClassCnn(hserializedItem);
			hserializedItem.Dispose();
			return hocrcnn;
		}

		// Token: 0x06000BD6 RID: 3030 RVA: 0x0004ADAA File Offset: 0x00048FAA
		object ICloneable.Clone()
		{
			return this.Clone();
		}

		// Token: 0x06000BD7 RID: 3031 RVA: 0x0004ADB4 File Offset: 0x00048FB4
		public new HOCRCnn Clone()
		{
			HSerializedItem hserializedItem = this.SerializeOcrClassCnn();
			HOCRCnn hocrcnn = new HOCRCnn();
			hocrcnn.DeserializeOcrClassCnn(hserializedItem);
			hserializedItem.Dispose();
			return hocrcnn;
		}

		/// <summary>Clear an CNN-based OCR classifier.</summary>
		/// <param name="OCRHandle">Handle of the OCR classifier.</param>
		// Token: 0x06000BD8 RID: 3032 RVA: 0x0004ADDC File Offset: 0x00048FDC
		public static void ClearOcrClassCnn(HOCRCnn[] OCRHandle)
		{
			HTuple htuple = HHandleBase.ConcatArray(OCRHandle);
			IntPtr proc = HalconAPI.PreCall(2046);
			HalconAPI.Store(proc, 0, htuple);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(OCRHandle);
		}

		/// <summary>
		///   Clear an CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		// Token: 0x06000BD9 RID: 3033 RVA: 0x0004AE20 File Offset: 0x00049020
		public void ClearOcrClassCnn()
		{
			IntPtr proc = HalconAPI.PreCall(2046);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Deserialize a serialized CNN-based OCR classifier.
		///   Modified instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="serializedItemHandle">Handle of the serialized item.</param>
		// Token: 0x06000BDA RID: 3034 RVA: 0x0004AE54 File Offset: 0x00049054
		public void DeserializeOcrClassCnn(HSerializedItem serializedItemHandle)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2053);
			HalconAPI.Store(proc, 0, serializedItemHandle);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(serializedItemHandle);
		}

		/// <summary>
		///   Classify multiple characters with an CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="character">Characters to be recognized.</param>
		/// <param name="image">Gray values of the characters.</param>
		/// <param name="confidence">Confidence of the class of the characters.</param>
		/// <returns>Result of classifying the characters with the CNN.</returns>
		// Token: 0x06000BDB RID: 3035 RVA: 0x0004AEA8 File Offset: 0x000490A8
		public HTuple DoOcrMultiClassCnn(HRegion character, HImage image, out HTuple confidence)
		{
			IntPtr proc = HalconAPI.PreCall(2056);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, character);
			HalconAPI.Store(proc, 2, image);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			num = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, num, out confidence);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(character);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Classify multiple characters with an CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="character">Characters to be recognized.</param>
		/// <param name="image">Gray values of the characters.</param>
		/// <param name="confidence">Confidence of the class of the characters.</param>
		/// <returns>Result of classifying the characters with the CNN.</returns>
		// Token: 0x06000BDC RID: 3036 RVA: 0x0004AF20 File Offset: 0x00049120
		public string DoOcrMultiClassCnn(HRegion character, HImage image, out double confidence)
		{
			IntPtr proc = HalconAPI.PreCall(2056);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, character);
			HalconAPI.Store(proc, 2, image);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			string result;
			num = HalconAPI.LoadS(proc, 0, num, out result);
			num = HalconAPI.LoadD(proc, 1, num, out confidence);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(character);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Classify a single character with an CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="character">Character to be recognized.</param>
		/// <param name="image">Gray values of the character.</param>
		/// <param name="num">Number of best classes to determine. Default: 1</param>
		/// <param name="confidence">Confidence(s) of the class(es) of the character.</param>
		/// <returns>Result of classifying the character with the CNN.</returns>
		// Token: 0x06000BDD RID: 3037 RVA: 0x0004AF98 File Offset: 0x00049198
		public HTuple DoOcrSingleClassCnn(HRegion character, HImage image, HTuple num, out HTuple confidence)
		{
			IntPtr proc = HalconAPI.PreCall(2057);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, character);
			HalconAPI.Store(proc, 2, image);
			HalconAPI.Store(proc, 1, num);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num2 = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(num);
			HTuple result;
			num2 = HTuple.LoadNew(proc, 0, num2, out result);
			num2 = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, num2, out confidence);
			HalconAPI.PostCall(proc, num2);
			GC.KeepAlive(this);
			GC.KeepAlive(character);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Classify a single character with an CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="character">Character to be recognized.</param>
		/// <param name="image">Gray values of the character.</param>
		/// <param name="num">Number of best classes to determine. Default: 1</param>
		/// <param name="confidence">Confidence(s) of the class(es) of the character.</param>
		/// <returns>Result of classifying the character with the CNN.</returns>
		// Token: 0x06000BDE RID: 3038 RVA: 0x0004B020 File Offset: 0x00049220
		public string DoOcrSingleClassCnn(HRegion character, HImage image, HTuple num, out double confidence)
		{
			IntPtr proc = HalconAPI.PreCall(2057);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, character);
			HalconAPI.Store(proc, 2, image);
			HalconAPI.Store(proc, 1, num);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num2 = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(num);
			string result;
			num2 = HalconAPI.LoadS(proc, 0, num2, out result);
			num2 = HalconAPI.LoadD(proc, 1, num2, out confidence);
			HalconAPI.PostCall(proc, num2);
			GC.KeepAlive(this);
			GC.KeepAlive(character);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Classify a related group of characters with an CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="character">Characters to be recognized.</param>
		/// <param name="image">Gray values of the characters.</param>
		/// <param name="expression">Expression describing the allowed word structure.</param>
		/// <param name="numAlternatives">Number of classes per character considered for the internal word correction. Default: 3</param>
		/// <param name="numCorrections">Maximum number of corrected characters. Default: 2</param>
		/// <param name="confidence">Confidence of the class of the characters.</param>
		/// <param name="word">Word text after classification and correction.</param>
		/// <param name="score">Measure of similarity between corrected word and uncorrected classification results.</param>
		/// <returns>Result of classifying the characters with the CNN.</returns>
		// Token: 0x06000BDF RID: 3039 RVA: 0x0004B0A8 File Offset: 0x000492A8
		public HTuple DoOcrWordCnn(HRegion character, HImage image, string expression, int numAlternatives, int numCorrections, out HTuple confidence, out string word, out double score)
		{
			IntPtr proc = HalconAPI.PreCall(2058);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, character);
			HalconAPI.Store(proc, 2, image);
			HalconAPI.StoreS(proc, 1, expression);
			HalconAPI.StoreI(proc, 2, numAlternatives);
			HalconAPI.StoreI(proc, 3, numCorrections);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			HalconAPI.InitOCT(proc, 2);
			HalconAPI.InitOCT(proc, 3);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			num = HTuple.LoadNew(proc, 1, HTupleType.DOUBLE, num, out confidence);
			num = HalconAPI.LoadS(proc, 2, num, out word);
			num = HalconAPI.LoadD(proc, 3, num, out score);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(character);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Classify a related group of characters with an CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="character">Characters to be recognized.</param>
		/// <param name="image">Gray values of the characters.</param>
		/// <param name="expression">Expression describing the allowed word structure.</param>
		/// <param name="numAlternatives">Number of classes per character considered for the internal word correction. Default: 3</param>
		/// <param name="numCorrections">Maximum number of corrected characters. Default: 2</param>
		/// <param name="confidence">Confidence of the class of the characters.</param>
		/// <param name="word">Word text after classification and correction.</param>
		/// <param name="score">Measure of similarity between corrected word and uncorrected classification results.</param>
		/// <returns>Result of classifying the characters with the CNN.</returns>
		// Token: 0x06000BE0 RID: 3040 RVA: 0x0004B160 File Offset: 0x00049360
		public string DoOcrWordCnn(HRegion character, HImage image, string expression, int numAlternatives, int numCorrections, out double confidence, out string word, out double score)
		{
			IntPtr proc = HalconAPI.PreCall(2058);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, character);
			HalconAPI.Store(proc, 2, image);
			HalconAPI.StoreS(proc, 1, expression);
			HalconAPI.StoreI(proc, 2, numAlternatives);
			HalconAPI.StoreI(proc, 3, numCorrections);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			HalconAPI.InitOCT(proc, 2);
			HalconAPI.InitOCT(proc, 3);
			int num = HalconAPI.CallProcedure(proc);
			string result;
			num = HalconAPI.LoadS(proc, 0, num, out result);
			num = HalconAPI.LoadD(proc, 1, num, out confidence);
			num = HalconAPI.LoadS(proc, 2, num, out word);
			num = HalconAPI.LoadD(proc, 3, num, out score);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(character);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Return the parameters of a CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="genParamName">A tuple of generic parameter names. Default: "characters"</param>
		/// <returns>A tuple of generic parameter values.</returns>
		// Token: 0x06000BE1 RID: 3041 RVA: 0x0004B218 File Offset: 0x00049418
		public HTuple GetParamsOcrClassCnn(HTuple genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2072);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Return the parameters of a CNN-based OCR classifier.
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="genParamName">A tuple of generic parameter names. Default: "characters"</param>
		/// <returns>A tuple of generic parameter values.</returns>
		// Token: 0x06000BE2 RID: 3042 RVA: 0x0004B270 File Offset: 0x00049470
		public HTuple GetParamsOcrClassCnn(string genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2072);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Get the names of the parameters that can be used in get_params_ocr_class_cnn for a given CNN-based OCR classifier.
		///   Instance represents: Handle of OCR classifier.
		/// </summary>
		/// <returns>Names of the generic parameters.</returns>
		// Token: 0x06000BE3 RID: 3043 RVA: 0x0004B2C0 File Offset: 0x000494C0
		public HTuple QueryParamsOcrClassCnn()
		{
			IntPtr proc = HalconAPI.PreCall(2081);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Read an CNN-based OCR classifier from a file.
		///   Modified instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <param name="fileName">File name. Default: "Universal_Rej.occ"</param>
		// Token: 0x06000BE4 RID: 3044 RVA: 0x0004B308 File Offset: 0x00049508
		public void ReadOcrClassCnn(string fileName)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2082);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Serialize a CNN-based OCR classifier
		///   Instance represents: Handle of the OCR classifier.
		/// </summary>
		/// <returns>Handle of the serialized item.</returns>
		// Token: 0x06000BE5 RID: 3045 RVA: 0x0004B354 File Offset: 0x00049554
		public HSerializedItem SerializeOcrClassCnn()
		{
			IntPtr proc = HalconAPI.PreCall(2093);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HSerializedItem result;
			num = HSerializedItem.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}
	}
}
